package com.csdj.springboot_thymeleaf.controller;

import com.csdj.springboot_thymeleaf.pojo.User;
import com.csdj.springboot_thymeleaf.pojo.UserVO;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author zyq
 * @Date 2022/11/28 14:46
 * @ClassName: IndexController
 * @Description: TODO
 * @Version 1.0
 */
@Controller
public class IndexController {

    @GetMapping("/index")
    public String index(Model model){
        model.addAttribute("title","thyeleaf页面");
        model.addAttribute("msg","主页内容");

        UserVO userVO=new UserVO();
        userVO.setUsername("admin");
        userVO.setAge(20);
        userVO.setCreateTime(new Date());
        userVO.setIsVip(false);
        userVO.setSex(1);
        userVO.setTags(Arrays.asList("java","php","mysql","python"));

        model.addAttribute("user",userVO);

        Map<String,Object> map=new HashMap<>();
        map.put("name","lisi");
        map.put("age","20");
        map.put("addr","bj");
        model.addAttribute("userMap",map);

        return "index";
    }


    @GetMapping("/test/{age}")
    @ResponseBody
    public String test(@PathVariable("age") Integer age ){
        System.out.println(age);

        return "年龄："+age;
    }

    @PostMapping("/user")
    @ResponseBody
    public Map<String, Object> userInfo(User user){
        System.out.println(user);
        Map<String,Object> map=new HashMap<>();
        map.put("code","200");
        map.put("user",user);
        return map;
    }



}
